from thrift import Thrift
from thrift.protocol import TCompactProtocol
from thrift.transport import TSocket, TTransport

from py import *
from py.thrift.generated import PersonService, ttypes

try:
    tSocket=TSocket.TSocket('localhost',8899);
    tSocket.setTimeout(600)

    transport=TTransport.TFramedTransport(tSocket)
    protocol=TCompactProtocol.TCompactProtocol(transport)
    client=PersonService.Client(protocol)

    transport.open()
    person=client.getPersonByUserName("张三")
    print(person.username)


    print("---------------------")

    newPerson=ttypes.Person()
    newPerson.username="李四"
    newPerson.age=15
    newPerson.married=True

    client.savePerson(newPerson)
    transport.close()

except Thrift.TException as tx:
    print("%s" % tx.message)

